/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export { ApiError } from "./core/ApiError";
export { CancelablePromise, CancelError } from "./core/CancelablePromise";
export { OpenAPI } from "./core/OpenAPI";
export type { OpenAPIConfig } from "./core/OpenAPI";

export type { BaseResponse_boolean_ } from "./models/BaseResponse_boolean_";
export type { BaseResponse_LoginUserVO_ } from "./models/BaseResponse_LoginUserVO_";
export type { BaseResponse_long_ } from "./models/BaseResponse_long_";
export type { LoginUserVO } from "./models/LoginUserVO";
export { ModelAndView } from "./models/ModelAndView";
export type { PasswordResetRequest } from "./models/PasswordResetRequest";
export type { User } from "./models/User";
export type { UserLoginRequest } from "./models/UserLoginRequest";
export type { UserRegisterRequest } from "./models/UserRegisterRequest";
export type { UserVO } from "./models/UserVO";
export type { View } from "./models/View";

export { BasicErrorControllerService } from "./services/BasicErrorControllerService";
export { UserControllerService } from "./services/UserControllerService";
import { interceptors } from "@/interceptor/interceptor";
import store from "@/store";
import { Message } from "@arco-design/web-vue";

// ... existing code ...

// 添加请求拦截器
interceptors.request.push({
  onRequest: (config) => {
    console.log("请求拦截器");
    // 添加通用请求头
    config.headers = {
      ...config.headers,
      "x-custom-header": "value",
    };

    // 如果需要添加token
    const token = store.state.user.token;
    if (token) {
      config.headers = {
        ...config.headers,
        Authorization: `${token}`,
      };
    }

    return config;
  },
  onRequestError: (error) => {
    console.error("请求配置错误:", error);
    return Promise.reject(error);
  },
});
// 添加响应拦截器
// 添加响应拦截器
interceptors.response.push({
  onResponse: (result) => {
    console.log("响应拦截器", result);
    // 统一处理响应数据
    if (result.body?.code === 0) {
      return result.body.data; // 直接返回数据部分
    }
    // 处理业务错误
    const errorMessage = result.body?.message || "请求失败";
    console.error("业务错误:", errorMessage);
    if (errorMessage === "Token过期了") {
      Message.error("登录已过期，请重新登录");
      //store.commit("user/setToken", "");
      window.location.href = "/user/login";
    } else if (errorMessage === "用户在其他地方登录") {
      Message.error("用户在其他地方登录");
      window.location.href = "/user/login";
    }
    //  throw new Error(errorMessage);
  },
  onResponseError: (error) => {
    console.error("响应错误:", error);
    // 处理其他HTTP错误
    const errorMessage = error.body?.message || error.message || "网络请求失败";
    // return Promise.reject(new Error(errorMessage));
  },
});
